﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using KaoWuYouLibs.Model;
using KaoWuYouLibs.Common;

namespace KaoWuYouLibs.Dal
{
    public class Test_QuestionAccess
    {
        public bool AddQuestionID(int QuestionID, int TestPaperID, int Score)
        {
            SqlConnection conn = new SqlConnection(Tools.ConnString);
            try
            {
                conn.Open();
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = "INSERT INTO [Test-Question](TestPaperID, QuestionID, Score)  VALUES (@TestPaperID, @QuestionID, @Score)";
                cmd.Parameters.AddRange(new SqlParameter[] 
                { 
                    new SqlParameter("@QuestionID", QuestionID) ,
                    new SqlParameter("@TestPaperID", TestPaperID),
                    new SqlParameter("@Score", Score)
                });
                cmd.ExecuteNonQuery();
                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                conn.Close();
            }
        }

        public bool DeleteQuestionID(int QuestionID, int TestPaperID)
        {
            SqlConnection conn = new SqlConnection(Tools.ConnString);
            try
            {
                conn.Open();
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = "DELETE FROM Test-Question WHERE (QuestionID = @QuestionID) AND (TestPaperID = @TestPaperID)";
                cmd.Parameters.AddRange(new SqlParameter[] 
                { 
                    new SqlParameter("@QuestionID", QuestionID),
                    new SqlParameter("@TestPaperID", TestPaperID)
                });
                cmd.ExecuteNonQuery();
                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                conn.Close();
            }
        }

        public void ImportTestPaper(string testPaperFilePath)
        {
            throw new NotImplementedException();
        }
    }
}
